import { getUserProfile } from '@/api/system/user'
import { onMounted, reactive, ref, toRefs } from 'vue'
export function useProfile() {
  const activeTab = ref('userinfo')
  const state: any = reactive({
    user: {},
    roleGroup: {},
    postGroup: {},
  })

  const { user, roleGroup, postGroup } = toRefs(state)

  /** 获取用户信息  */
  function getUser() {
    getUserProfile().then((response: any) => {
      const { data } = response
      user.value = data.user
      roleGroup.value = data.roleGroup
      postGroup.value = data.postGroup
    })
  }

  onMounted(() => {
    getUser()
  })

  return {
    user,
    roleGroup,
    postGroup,
    activeTab,
  }
}
